import { loadEnv } from 'vite'

const path = require('path')

const envConfig = loadEnv('develop', path.resolve(process.cwd())) // 获取.env里的配置文件

const platMap: Record<string, any> = {
  dev: 'http://101.33.241.53:10204',
  // dev: 'https://o5x0903486.zicp.fun',
  // online: 'http://10.255.35.218:9300/',
  // dev: 'https://cloud-gateway-dev.ifyou.net/',
  // online: 'http://10.255.35.218:9300/',
}

export default (plat: string) => {
  const host = platMap[plat] || platMap.dev

  console.log('****************本地开发环境配置***********************')
  console.log('plat---', plat)
  console.log('host---', host)
  console.log('envConfig', envConfig)
  console.log('****************本地开发环境配置***********************')

  return {
    '/fe-request': {
      rewrite: (path: string) => path.replace(/^\/fe-request/, ''),
      target: host,
      changeOrigin: true
    },
    '/baidu': {
      rewrite: (path: string) => path.replace(/^\/baidu/, ''),
      target: envConfig.VITE_APP_URL_OCR,
      changeOrigin: true
    },
    '/for-business': {
      rewrite: (path: string) => path.replace(/^\/for-business/, ''),
      target: envConfig.VITE_BASE_URL,
      changeOrigin: true
    },
    '/gateway': {
      rewrite: (path: string) => path.replace(/^\/gateway/, ''),
      target: envConfig.VITE_APP_URL_GATEWAY,
      changeOrigin: true
    }
  }
}
